<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('门店产品列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li class="hidden">
                                <label>删除状态：</label>
                                <input type="text" name="deleted" value="N"/>
                            </li>
                            <li>
                                <label>门店名称：</label>
                                <input type="text" name="deptName"/>
                            </li>
                            <li>
                                <label>产品名称：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status" th:with="type=${@dict.getType('sys_yes_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="system:DeptProduct:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="system:DeptProduct:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:DeptProduct:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:DeptProduct:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:DeptProduct:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:DeptProduct:remove')}]];
        var diaohuorequest = [[${@permission.hasPermi('diaohuorequest')}]];
        var ruku = [[${@permission.hasPermi('ruku')}]];
        var statusDatas = [[${@dict.getType('sys_yes_no')}]];
        var prefix = ctx + "system/DeptProduct";
        var type = [[${type}]];

        var fistColueType = {"checkbox": true};
        if(type == 2){
            fistColueType = {"radio": true};
            $("#toolbar").addClass("hidden");
        }

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/edit/-1",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                sortName: "createTime",
                sortOrder: "desc",
                modalName: "门店产品",
                clickToSelect: true,
                columns: [
                fistColueType,
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'deptName',
                    title: '门店'
                },
                {
                    field: 'name',
                    title: '产品名称'
                },
                {
                    field: 'stock',
                    title: '库存',
                    sortable:true,
                },
<!--                {-->
<!--                    field: 'price',-->
<!--                    title: '原价',-->
<!--                    sortable:true,-->
<!--                },-->
<!--                {-->
<!--                    field: 'discount',-->
<!--                    title: '折扣率',-->
<!--                    sortable:true,-->
<!--                },-->
                {
                    field: 'images',
                    title: '产品图片',
                    formatter: function(value, row, index) {
                        var fileUrl = row.images;
                        if(fileUrl){
                            var fileUrls = fileUrl.split(",");
                            for(var i = 0 ; i < fileUrls.length;i ++){
                                if(i==0){
                                   return $.table.imageView(fileUrls[i]);
                                }
                            }
                        }
                    }
                },
                {
                    field: 'status',
                    title: '启用',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable:true
                },
                {
                    title: '操作',
                    align: 'center',
                    visible: type==2?false:true,
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + diaohuorequest + '" href="javascript:void(0)" onclick="cargo(\'' + row.id + '\',\'' + row.deptId + '\')"><i class="fa fa-edit"></i>发起调货</a> ');

                        actions.push('<a class="btn btn-success btn-xs ' + ruku + '" href="javascript:void(0)" onclick="rukuG(\'' + row.id + '\',\'' + row.deptId + '\')"><i class="fa fa-plus"></i>入库</a> ');
                       //actions.push('<a class="btn btn-success btn-xs ' + diaohuorequest + '" href="javascript:void(0)" onclick="mingxi(\'' + row.id + '\',\'' + row.deptId + '\')"><i class="fa fa-search"></i>出入库明细</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function cargo(productId,deptId){
            $.modal.open("申请调货", ctx + "system/DeptProductCargo/add?productId="+productId+"&deptSource="+deptId);
        }

        function submitHandler(index, layero) {
			//var data = $("#" + table.options.id).bootstrapTable('getSelections'); //获取选中行
			var data = $.table.selectFirstColumns(); //获取选中行的收列值
			var name = $.table.selectColumns('name');
			if (data == "") {
     			$.modal.alertWarning("请至少选择一条记录");
     			return;
     		}
     		// 父页面的变量
     		parent.doSubmitHandler(data[0],name);
			$.modal.close();
		}

		//入库
		function rukuG(productId,deptId){
            $.modal.open("商品入库", ctx + "system/deptPoductLog/add?productId="+productId+"&deptId="+deptId);
		}
    </script>
</body>
</html>